From f62b2345f463695ef0f8f79830cd76b6e0332821 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Sat, 13 Jan 2024 10:35:22 +0700
Subject: Refactor src migrate folder

---
 src/pages/shop/product/[slug].jsx | 118 ++------------------------------------
 1 file changed, 5 insertions(+), 113 deletions(-)

(limited to 'src/pages/shop/product/[slug].jsx')

diff --git a/src/pages/shop/product/[slug].jsx b/src/pages/shop/product/[slug].jsx
index 667373b4..73e8987c 100644
--- a/src/pages/shop/product/[slug].jsx
+++ b/src/pages/shop/product/[slug].jsx
@@ -1,114 +1,6 @@
-import Seo from '@/core/components/Seo';
-import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner';
-import { getIdFromSlug } from '@/core/utils/slug';
-import productApi from '@/lib/product/api/productApi';
-import PageNotFound from '@/pages/404';
-import dynamic from 'next/dynamic';
-import { useRouter } from 'next/router';
-import cookie from 'cookie';
-import axios from 'axios';
-import { useProductContext } from '@/contexts/ProductContext';
-import { useEffect } from 'react';
-import { updateItemCart } from '@/core/utils/cart';
+import ProductDetailPage, {
+  getServerSideProps,
+} from '~/pages/shop/product/[slug]';
 
-const BasicLayout = dynamic(() =>
-  import('@/core/components/layouts/BasicLayout')
-);
-const Product = dynamic(() =>
-  import('@/lib/product/components/Product/Product')
-);
-
-export async function getServerSideProps(context) {
-  const { slug } = context.query;
-  const cookies = context.req.headers.cookie;
-  const cookieObj = cookies ? cookie.parse(cookies) : {};
-  const auth = cookieObj.auth ? JSON.parse(cookieObj.auth) : {};
-  const tier = auth.pricelist ? auth.pricelist : false;
-
-  let response = await axios(
-    `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/product-detail?id=` +
-      getIdFromSlug(slug) +
-      '&auth=' +
-      tier
-  );
-  let product = response.data;
-  // let productSolr = await productApi({ id: getIdFromSlug(slug), headers: { Token: authToken } })
-  // let productSolr = null
-  if (product?.length == 1) {
-    product = product[0];
-  } else {
-    product = null;
-  }
-
-  return {
-    props: { product },
-  };
-}
-
-export default function ProductDetail({ product }) {
-  const router = useRouter();
-  const { setProduct } = useProductContext();
-
-  useEffect(() => {
-    if (product) {
-      setProduct(product);
-    }
-  }, [product, setProduct]);
-
-  useEffect(() => {
-    const { action, variantId, qty } = router.query;
-    const addToCart = async () => {
-      const data = {
-        productId: variantId,
-        quantity: qty,
-        selected: true,
-        programLineId: null,
-        source: action,
-      };
-
-      await updateItemCart(data);
-      const redirectURL =
-        action === 'buy' ? '/shop/checkout?source=buy' : '/shop/cart';
-      router.push(redirectURL);
-    };
-
-    if (action && variantId && qty) {
-      addToCart();
-    }
-  }, [router]);
-
-  if (!product) return <PageNotFound />;
-
-  return (
-    <BasicLayout>
-      <Seo
-        title={product?.name || '' + ' - Indoteknik.com' || ''}
-        description='Temukan pilihan produk B2B Industri &amp; Alat Teknik untuk Perusahaan, UMKM &amp; Pemerintah dengan lengkap, mudah dan transparan.'
-        openGraph={{
-          url: process.env.NEXT_PUBLIC_SELF_HOST + router.asPath,
-          images: [
-            {
-              url: product?.image,
-              width: 800,
-              height: 800,
-              alt: product?.name,
-            },
-          ],
-          type: 'product',
-        }}
-        additionalMetaTags={[
-          {
-            name: 'keywords',
-            content: `${product?.name}, Harga ${product?.name}, Beli ${product?.name}, Spesifikasi ${product?.name}`,
-          },
-        ]}
-      />
-      {!product && (
-        <div className='container mx-auto flex justify-center pt-10'>
-          <LogoSpinner width={36} height={36} />
-        </div>
-      )}
-      {product && <Product product={product} />}
-    </BasicLayout>
-  );
-}
+export { getServerSideProps };
+export default ProductDetailPage;
-- 
cgit v1.2.3

